package com.zhixin.fans.ks.ui.main.index;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.res.IndexModule;
import com.zhixin.fans.ks.ui.module.ModuleItemAdapter;

import java.util.List;

public class BusyModuleAdapter extends BaseQuickAdapter<IndexModule, BaseViewHolder> implements BaseQuickAdapter.OnItemClickListener {

//    int[] ids = new int[]{R.mipmap.ic_module_bg_1,R.mipmap.ic_module_bg_2,R.mipmap.ic_module_bg_3,R.mipmap.ic_module_bg_4};


    public BusyModuleAdapter(@Nullable List<IndexModule> data) {
        super(R.layout.item_busy_module_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, IndexModule item) {

        helper.setText(R.id.tv_module_name, item.getGc_name());




        Glide.with(mContext).asBitmap()
                .load(item.getGc_icon())
                .error(R.mipmap.ic_model_douyin)
//                .addListener(new RequestListener<Bitmap>() {
//                    @Override
//                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
//                        int color = Palette.from(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_model_douyin)).generate().getDarkVibrantColor(Color.parseColor("#333333"));
//                        helper.setTextColor(R.id.tv_module_name, color);
//                        return false;
//                    }
//
//                    @Override
//                    public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
//                        LogUtils.e("onLoadFailed");
//                        return false;
//                    }
//                })
                .into((ImageView) helper.getView(R.id.img_module_icon));

        RecyclerView mRvMenus = helper.getView(R.id.rv_module_menus);
        mRvMenus.setLayoutManager(new GridLayoutManager(mContext, 3));
        ModuleItemAdapter moduleItemAdapter = new ModuleItemAdapter(item.getGc_listCoodCategory());
        mRvMenus.setAdapter(moduleItemAdapter);
        moduleItemAdapter.setOnItemClickListener(this);


//        FrameLayout mLay = helper.getView(R.id.lay_bg);
//        mLay.setBackgroundResource(ids[helper.getLayoutPosition() % ids.length]);


    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        getOnItemClickListener().onItemClick(adapter, view, position);
    }
}
